//-----------------------------------
//An-extract-from-the-NeHe-tutorials-
//-----------------------------------

#ifndef MS3D_H
#define MS3D_H

#include <windows.h>
#include <stdio.h>
#include <gl\gl.h>

/* MS3D constants */
#define MS3D_TEXTURE_OFF false
#define MS3D_TEXTURE_ON  true


typedef struct MS3D_HEADER_TYP
	{
    char id[10];				//The ID number of the model (always "MS3D000000")
	int  version;				//The version number of the model
	} MS3D_HEADER, *MS3D_HEADER_PTR;

typedef struct MS3D_VERTEX_TYP
	{
	unsigned char flags;
	unsigned char refCount;
	char boneID;				//The bone ID (used for skeletal animation)
	float vertex[3];
	} MS3D_VERTEX, *MS3D_VERTEX_PTR;

typedef struct MS3D_TRIANGLE_TYP
	{
	unsigned short flags;
	unsigned short vertexIndices[3];
	float vertexNormals[3][3];
	float u[3];
	float v[3];
	unsigned char smoothingGroup;
	unsigned char groupIndex;
	} MS3D_TRIANGLE, *MS3D_TRIANGLE_PTR;

typedef struct MS3D_GROUP_TYP
	{
    unsigned char	flags;
    char			name[32];
    unsigned short	numTriangles;
	unsigned short*	triangleIndices;
	char			materialIndex;
	} MS3D_GROUP, *MS3D_GROUP_PTR;

class MS3D
{
    public:
		unsigned short numVertices;
		MS3D_VERTEX*   vertices;
		unsigned short numTriangles;
		MS3D_TRIANGLE* triangles;
		unsigned short numGroups;
		MS3D_GROUP*	   groups;

	MS3D()
	{}

	~MS3D()
	{	
		if(vertices)
			delete vertices;		
		if(triangles)
			delete triangles;
		if(groups)
			delete groups;
	}

	bool LoadMS3D(char* filename);
	void RenderMS3D(void);

};

#endif

